package com.yyx.app1.Question_function.Control.ChatListView;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.yyx.app1.Data.BaseDataManager;
import com.yyx.app1.Data.testDate;
import com.yyx.app1.MyApp;
import com.yyx.app1.R;
import com.yyx.app1.tool.ImageTool;
import com.yyx.app1.ui.ImageShower_Activity;
import com.yyx.app1.ui.ImageShower_Activity_;

import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

/**
 * Created by yuexing on 2015/9/24.
 */
@EViewGroup(R.layout.itemview_mysay_listview_chat)
public class ItemView_ChatListView_my extends LinearLayout {
    private Context context;
    @ViewById
    ImageView chat_portrait_my;

    @ViewById
    LinearLayout chat_image;

    @ViewById
    TextView chat_character;

    public ItemView_ChatListView_my(Context context) {
        super(context);
        this.context=context;
    }

    public ItemView_ChatListView_my(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context=context;
    }

    public ItemView_ChatListView_my(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context=context;
    }

    public void bind_SendImage(String url)
    {
        url = new testDate().strings[7];
        chat_image.setVisibility(VISIBLE);
        chat_character.setVisibility(GONE);
        setMyPortrait();
        chat_image.removeAllViews();
        for (int i =0 ; i<1;++i)
        {
            ImageView imageView=new ImageView(context);
            imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT));
            imageView.setScaleType(ImageView.ScaleType.CENTER);
            ImageLoader imageLoader = BaseDataManager.getMyImageLoader(context);
            imageLoader.get(url, imageLoader.getImageListener(imageView, testDate.loadImageRes,testDate.defaultMedicationImage), ImageTool.dip2px(context, 250), ImageTool.dip2px(context, 250));
            Bundle tag = new Bundle();
            tag.putString("value", url);
            tag.putString("type", "URL");
            ImageShower_Activity.setTagOnClickListener(imageView, context, tag);
            chat_image.addView(imageView);
        }
    }

    public void bind_SendImage(Uri uri)
    {
        try {
            chat_image.setVisibility(VISIBLE);
            chat_character.setVisibility(GONE);
            setMyPortrait();
            chat_image.removeAllViews();
            for (int i = 0; i < 1; ++i) {
                ImageView imageView = new ImageView(context);
                imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                imageView.setScaleType(ImageView.ScaleType.CENTER);
                Bitmap bitmap = BaseDataManager.getMyBaseDataManager(context).getUri(uri, ImageTool.dip2px(context, 250), ImageTool.dip2px(context, 250), true);
                Log.i("正常1", uri + "W" + bitmap.getRowBytes() / 4 + "H" + bitmap.getHeight());
                imageView.setImageBitmap(bitmap);
                Bundle tag = new Bundle();
                tag.putParcelable("value", uri);
                tag.putString("type", "URI");
                ImageShower_Activity.setTagOnClickListener(imageView, context, tag);
                chat_image.addView(imageView);
            }
        }
        catch (Exception e)
        {
            Log.e("异常1511021422",e.toString());
        }
    }

    public void bind_SendText(String str)
    {
        setMyPortrait();
        chat_character.setVisibility(VISIBLE);
        chat_character.setText(str);
        chat_image.setVisibility(GONE);
    }

    private void setMyPortrait()
    {
        ImageLoader imageLoader = BaseDataManager.getMyImageLoader(context);
        imageLoader.get(BaseDataManager.getMyBOSSInfo(context).getPortraitURL(), imageLoader.getImageListener(chat_portrait_my, testDate.loadImageRes,testDate.defaultPortrait), ImageTool.dip2px(context, 40), ImageTool.dip2px(context, 40));
        Bundle tag = new Bundle();
        tag.putString("type","URL");
        tag.putString("value",BaseDataManager.getMyBOSSInfo(context).getPortraitURL());
        ImageShower_Activity.setTagOnClickListener(chat_portrait_my,context,tag);
    }
}
